package com.mqb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.security.web.session.HttpSessionEventPublisher;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

/**
 * @author mqb
 * @date 2021/4/7 9:32
 */
@Configuration
@EnableRedisHttpSession
public class CustomRedisHttpSessionConfig {

    private final RedisSerializer<Object> redisSerializer;

    public CustomRedisHttpSessionConfig(RedisSerializer<Object> redisSerializer) {
        this.redisSerializer = redisSerializer;
    }

    /**
     * 修改 SpringSession redis 序列化方式
     * 注意这个beanName必须是 springSessionDefaultRedisSerializer
     * @return
     */
    @Bean
    public RedisSerializer springSessionDefaultRedisSerializer() {
        return redisSerializer;
    }

    @Bean
    public HttpSessionEventPublisher httpSessionEventPublisher() {
        return new HttpSessionEventPublisher();
    }
}
